<html>
<head><meta charset="utf-8"><title>Experimenting with covariant associated types. · wg-traits · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/index.html">wg-traits</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Experimenting.20with.20covariant.20associated.20types.2E.html">Experimenting with covariant associated types.</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="216827738"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Experimenting%20with%20covariant%20associated%20types./near/216827738" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Avi Dessauer <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Experimenting.20with.20covariant.20associated.20types.2E.html#216827738">(Nov 16 2020 at 02:41)</a>:</h4>
<p>If I wanted to experiment with adding a way to make associated types covariant would the appropriate method be via  a<code>#[covariant]</code> attribute on trait and GAT parameters?</p>
<p>Would this require support from chalk?</p>



<a name="216876776"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Experimenting%20with%20covariant%20associated%20types./near/216876776" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yulia Startsev <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Experimenting.20with.20covariant.20associated.20types.2E.html#216876776">(Nov 16 2020 at 14:21)</a>:</h4>
<p>(deleted)</p>



<a name="216877519"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Experimenting%20with%20covariant%20associated%20types./near/216877519" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Experimenting.20with.20covariant.20associated.20types.2E.html#216877519">(Nov 16 2020 at 14:27)</a>:</h4>
<p>eventually</p>



<a name="216877538"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Experimenting%20with%20covariant%20associated%20types./near/216877538" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Experimenting.20with.20covariant.20associated.20types.2E.html#216877538">(Nov 16 2020 at 14:27)</a>:</h4>
<p>we'd want to check that lifetime parametrs are used in the right places</p>



<a name="216877558"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Experimenting%20with%20covariant%20associated%20types./near/216877558" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Experimenting.20with.20covariant.20associated.20types.2E.html#216877558">(Nov 16 2020 at 14:27)</a>:</h4>
<p>and it would affect the subtyping logic</p>



<a name="216964914"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Experimenting%20with%20covariant%20associated%20types./near/216964914" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Avi Dessauer <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Experimenting.20with.20covariant.20associated.20types.2E.html#216964914">(Nov 17 2020 at 04:12)</a>:</h4>
<p>When using this hypothetical attribute would the planned type equality constraint be covariant?<br>
If  not could <code>for&lt;#[covariant] 'a&gt; Self::Bar&lt;'a&gt; == Self</code>suffice?</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">trait</span><span class="w"> </span><span class="n">Inject</span><span class="w"> </span><span class="k">where</span><span class="w"> </span><span class="k">for</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="w"> </span><span class="bp">Self</span>::<span class="n">Bar</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="bp">Self</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Life</span><span class="o">&lt;</span><span class="cp">#[covariant]</span><span class="w"> </span><span class="o">'</span><span class="na">l</span><span class="o">&gt;</span>: <span class="o">'</span><span class="na">l</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="w"> </span><span class="n">Inject</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="o">&amp;'</span><span class="na">a</span><span class="w"> </span><span class="kt">str</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Life</span><span class="o">&lt;'</span><span class="na">l</span><span class="o">&gt;</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;'</span><span class="na">l</span><span class="w"> </span><span class="kt">str</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>Thanks</p>



<a name="216976624"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Experimenting%20with%20covariant%20associated%20types./near/216976624" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Avi Dessauer <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Experimenting.20with.20covariant.20associated.20types.2E.html#216976624">(Nov 17 2020 at 08:29)</a>:</h4>
<p>Oops made typo there. <code>Self::Bar</code> should have been <code>Self::Life</code></p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">trait</span><span class="w"> </span><span class="n">Inject</span><span class="w"> </span><span class="k">where</span><span class="w"> </span><span class="k">for</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="w"> </span><span class="bp">Self</span>::<span class="n">Life</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="bp">Self</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Life</span><span class="o">&lt;</span><span class="cp">#[covariant]</span><span class="w"> </span><span class="o">'</span><span class="na">l</span><span class="o">&gt;</span>: <span class="o">'</span><span class="na">l</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="w"> </span><span class="n">Inject</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="o">&amp;'</span><span class="na">a</span><span class="w"> </span><span class="kt">str</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Life</span><span class="o">&lt;'</span><span class="na">l</span><span class="o">&gt;</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;'</span><span class="na">l</span><span class="w"> </span><span class="kt">str</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="216977207"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/144729-wg-traits/topic/Experimenting%20with%20covariant%20associated%20types./near/216977207" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Avi Dessauer <a href="https://rust-lang.github.io/zulip_archive/stream/144729-wg-traits/topic/Experimenting.20with.20covariant.20associated.20types.2E.html#216977207">(Nov 17 2020 at 08:37)</a>:</h4>
<p>Would one of these prove <code>T == T::Life&lt;'_&gt;</code> ?</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">trait</span><span class="w"> </span><span class="n">Inject</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Life</span><span class="o">&lt;</span><span class="cp">#[covariant]</span><span class="w"> </span><span class="o">'</span><span class="na">l</span><span class="o">&gt;</span>: <span class="o">'</span><span class="na">l</span> <span class="o">+</span><span class="w"> </span><span class="k">for</span><span class="o">&lt;</span><span class="cp">#[covariant]</span><span class="w"> </span><span class="o">'</span><span class="na">a</span><span class="o">&gt;</span><span class="w"> </span><span class="n">Inject</span><span class="o">&lt;</span><span class="n">Life</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="bp">Self</span><span class="o">&gt;</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">trait</span><span class="w"> </span><span class="n">Inject</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Life</span><span class="o">&lt;</span><span class="cp">#[covariant]</span><span class="w"> </span><span class="o">'</span><span class="na">l</span><span class="o">&gt;</span>: <span class="o">'</span><span class="na">l</span> <span class="o">+</span><span class="w"> </span><span class="n">Inject</span><span class="o">&lt;</span><span class="n">Life</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="bp">Self</span><span class="o">&gt;</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="w"> </span><span class="n">Inject</span><span class="o">&lt;'</span><span class="na">a</span><span class="o">&gt;</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="o">&amp;'</span><span class="na">a</span><span class="w"> </span><span class="kt">str</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Life</span><span class="o">&lt;'</span><span class="na">l</span><span class="o">&gt;</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;'</span><span class="na">l</span><span class="w"> </span><span class="kt">str</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>